import junit.framework.*;
import java.util.*;
import java.sql.*;
import java.sql.Date;


public class methodTests extends TestCase{

  protected void setUp() throws Exception{
    super.setUp();
  }
  
  // By Brian Gardner
  public void testCreatePatient(){
    String validUsername = "username";
    String invalidUsername = "";
    String validPassword = "password";
    String invalidPassword = "";

    boolean success = Patient.createPatient(validUsername, validPassword, false);
    assertTrue(success);

    boolean failure = Patient.createPatient(invalidUsername, validPassword, false);
    assertFalse(failure);

    boolean anotherFailure = Patient.createPatient(validUsername, invalidPassword, false);
    assertFalse(anotherFailure);

    //cleanup so the test runs correctly
    boolean deleted = Patient.deletePatient(validUsername);
  }
  
  // By Hayson Tsang
  // This method tests the updateTreatmentRecord method of TreatmentRecord.java
  @SuppressWarnings("deprecation")
  public void testUpdateTreatmentRecord(){
	  
	  String validUsername="immmaaaacrazzyyyyyyy";
	  String encryptedPass="CdNmzucGgk89wavyh1Qpie2tDAUMSK";
	  boolean suspended=false;
	  Patient.createPatient(validUsername, encryptedPass, suspended);
	  Date appt_Date=new Date(2014, 3, 14);
	  Time appt_Time=new Time(14, 30, 0);
	  Appointment.createAppointment(validUsername, appt_Date, appt_Time);
	  int AppointmentId=Appointment.findAppointmentId(validUsername, appt_Date, appt_Time);
	  String newDiagnosis="Patient has cancer.";
	  
	  // updateTreatmentRecord should return false if the treatmentRecord was never created.
	  boolean failure1=TreatmentRecord.updateTreatmentRecord(validUsername, AppointmentId, newDiagnosis);
	  assertFalse(failure1);
	  
	  // updateTreatmentRecord should return false if the user was never created.
	  String invalidUsername="iamauserthatwasnevercreated";
	  boolean failure2=TreatmentRecord.updateTreatmentRecord(invalidUsername, AppointmentId, newDiagnosis);
	  assertFalse(failure2);
	  
	  String diagnosisUnknown="Unknown. Awaiting diagnosis.";
	  TreatmentRecord.createTreatmentRecord(validUsername, AppointmentId, diagnosisUnknown);
	  
	  // updateTreatmentRecord should return true if the user and the treatmentRecord has been created.
	  boolean success=TreatmentRecord.updateTreatmentRecord(validUsername, AppointmentId, newDiagnosis);
	  assertTrue(success);
	  
	  // clean up
	  TreatmentRecord.deleteTreatmentRecord(validUsername, AppointmentId);
	  Appointment.deleteAppointment(AppointmentId);
	  Patient.deletePatient(validUsername);
  }
  
  /**
   * Tests VitalSigns.readVitalSigns(String username, int recordId);
   * @author Ted Liu
   */
  @SuppressWarnings("deprecation")
  public void testReadVitalSigns(){
    String username = "theballsareinert";
    String encryptedPass = "1337133713371337";
    Patient.createPatient(username, encryptedPass, false);

    Date appointmentDate = new Date(2340, 2, 29);
    Time appointmentTime = new Time(13, 37, 0);
    Appointment.createAppointment(username, appointmentDate, appointmentTime);

    int appointmentId = Appointment.findAppointmentId(username, appointmentDate, appointmentTime);
    String diagnosis = "the balls are inert";
	  TreatmentRecord.createTreatmentRecord(username, appointmentId, diagnosis);

    int treatmentRecordId = TreatmentRecord.findTreatmentRecordId(username, appointmentId, diagnosis);
    VitalSigns.createVitalSigns(username, treatmentRecordId, 90, 90, 90, 90, 90);

    assert(VitalSigns.readVitalSigns(username,                         treatmentRecordId)     != null);
    assert(VitalSigns.readVitalSigns(username,                         treatmentRecordId - 1) == null);
    assert(VitalSigns.readVitalSigns(username + "itwasinmyotherpants", treatmentRecordId)     == null);
    assert(VitalSigns.readVitalSigns(username + "itwasinmyotherpants", treatmentRecordId - 1) == null);
  }
  
  // By Vishwaja Cheruku
  public void testCreateDoctorsOrders(){
	  String validUsername = "username";
	  String invalidUsername = "";
	  String validTitle = "title";
	  String invalidTitle = "";
	  String validFirst="first";
	  String invalidFirst="";
	  String validMiddle=""; 
	  String validLast="last"; 
	  String invalidLast="last";

	  boolean worked = Name.createName(validUsername, validTitle, validFirst, validMiddle, validLast);
	  assertTrue(success);

	  boolean fail = Name.createName(invalidUsername, invalidTitle, invalidFirst,"", invalidLast);
	  assertFalse(failure);
  
  }
} 
